define(["jquery","framework", "layer_m", "_template", "_queryConditions","_global","_cartData"],
    function ($,framework, layer, template,_qc,_gl,_CD) {
    function init() {
        var url = _gl.getAjaxUrl().netPoint;
        var loadIndex = framework.load();
        var post = $.post(url, {
            pageno: '1',
            pagesize: '1000',
            deviceid: document.getElementById("defaultDeviceId").value,
            districtid:  0
        }, function (data) {
            framework.close(loadIndex);
            var d = data;
            var tData = {
                ListArea: d.result.ListArea,
                areaId: d.districtid,
                areaNow: 0
            };
            var netPointDialogIndex = layer.open({
                type: 1,
                title: false,
                closeBtn: 1,
                shadeClose: true,
                content: template("templateNetPointDialog", tData)
            });

            $("#netPointListContainer").html(template("templateNetPointList", d.result.PageInfo));

            $("#netPointDialog-closeBtn").off("click").on("click", function () {
                framework.close(netPointDialogIndex);
            });

            $("#netPointListContainer").off("click").on("click", ".netPoint-item", function () {
                var $this = $(this);
                framework.prodCookie().setNetPoint({
                    id: $this.attr("data-id"),
                    name: $this.attr("data-name"),
                    address: $this.attr("data-address")
                });
                _CD.clear();
                window.location.href = _gl.getHref();
            });

            var isClick = true;

            $("#netPointAreaList").on("click", "a", function () {
                var $this = $(this);
                if (isClick) {
                    isClick = false; 
                    $("#netPointAreaList a").removeClass("active");
                    $this.addClass("active");
                    var xLoad = _gl.load();
                     var post = $.post(url, {
                         pageno: '1',
                         pagesize: '1000',
                         deviceid: document.getElementById("defaultDeviceId").value,
                         districtid: $this.attr("data-id")
                     }, function (data) {
                         _gl.close(xLoad);
                         var d = data;
                         $("#netPointListContainer").html(template("templateNetPointList", d.result.PageInfo));
                         isClick = true;
                     });
                }
            });
        });
    }
    return {
        init: init
    }
});